
capture log close
log using $log/AED_analysis_01_dynamics, text replace

/* ------------------------------------------------------------------------------------ */
/* --- Estimation results Figure 1 ---------------------------------------------------- */
/* ------------------------------------------------------------------------------------ */ 


clear
clear matrix
clear mata
set maxvar 10000
set matsize 2000
set more off

set trace off
   
#d;
global xvars " vac_rate aloq   
				share_agriculture_avg share_industry_avg share_service_avg wanderungen_avg bip_avg 
				iza_alter_kat1 iza_alter_kat2 iza_alter_kat3 iza_alter_kat4 iza_sex iza_famstd
				i.iza_kind i.iza_abschluss_kat i.iza_ausb_kat
				iza_last_daily_income i.iza_beruf_kat
				iza_ende_last iza_vztz_last iza_zeit_la
				iza_sv_tminus1 iza_sv_tminus2 iza_sv_tminus3
				iza_lnwage_tminus1 iza_lnwage_tminus2 iza_lnwage_tminus3 
				i.year i.entry_m";
				#d cr
				

		use $data/data_est_border, clear
		
		*Restrict to same inflows as in survey
		keep if eintritt<=200805 & eintritt>=200706
	
	bys pers_id: gen insample = 1 if _n==1
			
	
	forvalues t=2/24 {
		
		
		qui reg sv_tplus_`t' log_intensity_alt $xvars pair_* [pw=1/fweight_reg], cluster(ba)
		matrix b=e(b)'
		matrix n=e(N)
		matrix v=e(V)
		matrix se=vecdiag(cholesky(diag(vecdiag(v[1..1,1..1]))))'
		matrix d`t'_sv=b[1..1,1..1],se
		
		qui reg daily_income_tplus_`t' log_intensity_alt $xvars pair_* [pw=1/fweight_reg], cluster(ba)
		matrix b=e(b)'
		matrix n=e(N)
		matrix v=e(V)
		matrix se=vecdiag(cholesky(diag(vecdiag(v[1..1,1..1]))))'
		matrix d`t'_geld=b[1..1,1..1],se
		
		
		
		
	}
	
	


#d;	
matrix d_sv = d2_sv\d3_sv\d4_sv\d5_sv\d6_sv\d7_sv\d8_sv\d9_sv\d10_sv\d11_sv\d12_sv\
d13_sv\d14_sv\d15_sv\d16_sv\d17_sv\d18_sv\d19_sv\d20_sv\d21_sv\d22_sv\d23_sv\d24_sv
;
#d cr

#d;	
matrix d_geld = d2_geld\d3_geld\d4_geld\d5_geld\d6_geld\d7_geld\d8_geld\d9_geld\d10_geld\d11_geld\d12_geld\
d13_geld\d14_geld\d15_geld\d16_geld\d17_geld\d18_geld\d19_geld\d20_geld\d21_geld\d22_geld\d23_geld\d24_geld
;
#d cr



#d;
matrix rownames d_sv =
"Month 2" 
"Month 3" 
"Month 4" 
"Month 5" 
"Month 6" 
"Month 7" 
"Month 8" 
"Month 9" 
"Month 10" 
"Month 11" 
"Month 12" 
"Month 13" 
"Month 14" 
"Month 15" 
"Month 16" 
"Month 17" 
"Month 18" 
"Month 19" 
"Month 20" 
"Month 21" 
"Month 22" 
"Month 23" 
"Month 24" 
;
#d cr

#d;
matrix rownames d_geld =
"Month 2" 
"Month 3" 
"Month 4" 
"Month 5" 
"Month 6" 
"Month 7" 
"Month 8" 
"Month 9" 
"Month 10" 
"Month 11" 
"Month 12" 
"Month 13" 
"Month 14" 
"Month 15" 
"Month 16" 
"Month 17" 
"Month 18" 
"Month 19" 
"Month 20" 
"Month 21" 
"Month 22" 
"Month 23" 
"Month 24" 
;
#d cr
mat list colnames d_geld = "Coef" "SE"
mat list colnames d_sv = "Coef" "SE"

mat list d_sv
mat list d_geld

log close
